'use strict';
const BaseController = require('./base');
const { dislikeRules, cancleDislikeRules } = require('../validator/themeDislike');
class ThemeDislike extends BaseController {

  // 不喜欢的话题用户
  async dislike() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(dislikeRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const data = ctx.request.body;
    const user_id = ctx.helper.decodeJwt(ctx);
    const res = await service.themeDislike.dislike({
      ...data,
      user_id,
    });
    ctx.helper.success({ bean: res }, '不喜欢话题成功！');
  }

  // 不喜欢的评论
  async cancleDislike() {
    const { ctx, service, app } = this;
    const errors = app.validator.validate(cancleDislikeRules, ctx.request.body);
    errors && ctx.helper.commonErr('参数错误', { beans: errors });
    const { id } = ctx.request.body;
    const res = await service.themeDislike.cancleDislike(id);
    if (!res) ctx.helper.success({}, '取消不喜欢话题成功！');
    ctx.helper.success({ bean: res }, '取消不喜欢话题成功！');
  }
}

module.exports = ThemeDislike;
